<script setup>
import HelloWorld from './components/HelloWorld.vue'
import {ref, watch, computed, onMounted, provide} from 'vue'
import { useStore } from "/src/pinia.js"
import {storeToRefs} from "pinia";
const isDark = ref(false)
const list = ref([1, 2, 3, 4, 5])
const computedList = computed(() => {
  return list.value.filter((item) => item % 2 === 0)
})
console.log(computedList.value)
watch(isDark, (newValue) => {
  document.documentElement.classList.toggle('dark', newValue)
})
const jsons = ref('')
const sonMsg = (msg) => {
  jsons.value = msg
}
const hello = ref(null)
onMounted(() => {
  console.log(hello.value)
  store.getList()
})
provide('isDark', isDark)//key 和 value可响应/方法可调用
setTimeout(() => {
  isDark.value = true
}, 3000)
watch(isDark, () => {
  console.log("turn")
})
const store = useStore()
const countBtn = ref(null)
const {state, doubleCount} = storeToRefs(store)//只能用于数据可响应，方法不需要storeToRefs
</script>

<template>
  <h1 style="color: white">{{ jsons }}</h1>
  <button ref="countBtn" @click="store.increment()">{{ store.state.count }}</button>
  {{ store.doubleCount }}
  <button @click="store.increment()">{{ state.count }}</button>
  {{ doubleCount }}
  <header>
    <img alt="Vue logo" class="logo" src="./assets/logo.svg" width="125" height="125" />

    <div class="wrapper">
      <HelloWorld msg="You did it!" @get-message="sonMsg" ref="hello"/>
    </div>
  </header>
  <ul>
    <li v-for="item in store.list" :key="item">{{ item }}</li>
  </ul>

</template>

<style scoped>
header {
  line-height: 1.5;
}

.logo {
  display: block;
  margin: 0 auto 2rem;
}

@media (min-width: 1024px) {
  header {
    display: flex;
    place-items: center;
    padding-right: calc(var(--section-gap) / 2);
  }

  .logo {
    margin: 0 2rem 0 0;
  }

  header .wrapper {
    display: flex;
    place-items: flex-start;
    flex-wrap: wrap;
  }
}
</style>
